import service, { get, post } from '@/utils/request';
import config from '@/config/index.js';

// import md5 from 'js-md5'
const servletMap = [
	// [ '/web/user/isLogin', 'isLogin'  ,'post'],
	// [ '/web/guide/queryGuide', 'queryGuide' ,'post' ],
	// [ '/web/user/getUserInfo', 'getUserInfo'  ,'post'],
	//
	// [ '/web/opencourse/getOpenCourseTags', 'getOpenCourseTags' ,'post' ],
	// [ '/web/index/getMyLivePlan', 'getMyLivePlan' ,'post' ],
	// [ '/web/index/findAppDowConfig', 'findAppDowConfig'  ,'post'],
	// [ '/web/user/limit/warn', 'warn'  ,'post'],
	// [ '/web/uc/affiche/countReceiveAffiche', 'countReceiveAffiche'  ,'post'],
	// [ '/web/opencourse/queryOpenCoursePage', 'queryOpenCoursePage'  ,'post'],
	// [ '/web/user/login/initLoginQrCode', 'initLoginQrCode'  ,'post'],
	// [ '/web/user/login/getLoginQrCodeStatus', 'getLoginQrCodeStatus'  ,'post'],
	// [ '/web/user/doLogin', 'doLogin' ],
	// [ '/web/user/ajax/retrievePassword', 'retrievePassword' ,'post'],
	
	['/user/login','login','post'],

	['/exam/category/setting-choose','settingChoose','post'],
	['/exam/category/current-choose','currentChoose','get'],
	['/exam/calendar/latest-date','latestDate','get'],
	['/exam/calendar/get-calendar-list','getCalendarList','get'],
	['/user/sys/teacher/list','teacherList','get']

	
	// {
	// 	"type": "string",
	// 	"deviceType": "string",
	// 	"deviceId": "string",
	// 	"deviceName": "string",
	// 	"devicePushId": "string",
	// 	"userAccount": "string",
	// 	"credential": "string",
	// 	"code": "string",
	// 	"userType": "channelBusiness",
	// 	"userTypes": [
	// 	  "channelBusiness"
	// 	],
	// 	"userId": "string",
	// 	"bindPhone": "string",
	// 	"groupId": 0,
	// 	"token": "string",
	// 	"accessToken": "string"
	//   }
];
let obj = {};
for (let i in servletMap) {
	obj[servletMap[i][1]] = function() {
		return service[servletMap[i][2]](servletMap[i][0], ...arguments);
	};
}

export default {
	...obj,
	bannerList: function(params) {
		return get('/banners/list', params, { pass: true });
	},
	phone_code: function(params) {
        let now =new Date()
        const timestamp=now.getTime()
        const md5Hash=CryptoJS.MD5(config.smsSignKey+timestamp+params.phone)
        const finalStr=md5Hash.toString(CryptoJS.enc.Hex)

        // let encryptedData  = CryptoJS.AES.encrypt("加密的内容", key, {
        //     mode: CryptoJS.mode.ECB,
        //     padding: CryptoJS.pad.Pkcs7
        // });
        // let hexData = encryptedData.ciphertext.toString();
      

        // const finalStr=md5.hex(config.smsSignKey+timestamp+params.phone)


        // const key=CryptoJS.enc.Utf8.parse(config.smsSignKey);
        // const iv=CryptoJS.enc.Utf8.parse(params.phone);
        // const encryptedContent = CryptoJS.AES.encrypt(config.smsSignKey+timestamp+params.phone, key, {
        //     iv: iv,
        //     mode: CryptoJS.mode.CBC,  
        //     padding: CryptoJS.pad.Pkcs7
        // })
        // const finalStr = encryptedContent.ciphertext.toString()
        
		return get('/user/cu/sms/phone-code/' + params.phone, { ...params,sign:finalStr,timestamp }, { pass: true });
	},

	logout :function(params) {
		return get('/user/logout', null, { pass: true });
	},
	register :function(params) {
		return post('/user/register', params, { pass: true });
	},
	forget_pass:function(params) {
		return post('/user/forget-pass', params, { pass: true });
	},
};
